import cv2, time
import numpy as np
from src.data.structures import BinocularImagePair


class OSD:
    def __init__(self, window: str = "StereoLive"):
        self.window = window
        # 延迟到第一帧再创建窗口
        self._initialized = False

    def draw(self, pair: BinocularImagePair, fps: float, drops: int, help_text: str):
        if not self._initialized:
            cv2.namedWindow(self.window, cv2.WINDOW_KEEPRATIO)
            cv2.resizeWindow(
                self.window, pair.left_image.shape[1] * 2, pair.left_image.shape[0]
            )
            self._initialized = True

        vis = np.hstack([pair.left_image, pair.right_image])
        cv2.putText(
            vis,
            f"FPS:{fps:.1f}  Drops:{drops}",
            (10, 30),
            cv2.FONT_HERSHEY_SIMPLEX,
            0.7,
            (0, 255, 0),
            2,
        )
        cv2.putText(
            vis, help_text, (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 0), 1
        )
        cv2.imshow(self.window, vis)
